<template>
  <div class="tabbar">
    <div class="tabbar_box" v-for="(item, index) in tabbarData" :key="index">
      <div
        class="tabbar_item"
        @click="itemClick(item, index)"
        :class="{ active: currentIndex === index }"
      >
        <img
          :src="
            getAssetsImgUrl(
              currentIndex !== index ? item.image : item.imageActive
            )
          "
          alt=""
        />
        <span>{{ item.text }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import tabbarData from "@/assets/data/tabbar.js";
import { getAssetsImgUrl } from "@/utils/load_assets.js";
import { ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();

const currentIndex = ref(0); //选中下标

const itemClick = (item, index) => {
  //路由跳转
  router.push(item.path);
  //图标选中
  currentIndex.value = index;
};
</script>

<style scoped lang="scss">
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  display: flex;
  border-top: 2px solid #eee;
  background: #fff;
  .tabbar_box {
    flex: 1;
    .tabbar_item {
      height: 100%;
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-around;
      flex-direction: column;

      &.active {
        color: var(--primary-color);
      }
      img {
        width: 36px;
      }
      span {
        font-size: 12px;
      }
    }
  }
}
</style>
